<?php
/**
 * @ClassName: HandleLogic
 * @Description: 辅助函数、公共函数
 * @author: gydtrade
 * @Date: 2025-09-26 15:53
 * @Version: V1.0.0
 */

namespace app\common\rebate;

use app\common\logic\MemberLogic;
use app\common\model;

class HandleLogic
{
    public $msg = []; // 消息

    public $order_sn = ""; // 订单号

    public $orderInfo = []; // 订单信息

    /**
     * 获取订单信息
     * @param $order_sn
     * @return void
     */
    public function getOrderByOrderSn($order_sn)
    {
        $this->order_sn = $order_sn;

        $this->orderInfo = model\ShopOrder::where('order_sn', $order_sn)->find();
    }

    /**
     * 获取下单人的信息
     * @param $order
     * @return array
     */
    public function getBuyer($order)
    {
        if (!$order) {
            return ['code' => 0, 'msg' => '没有订单信息'];
        }

        $member = model\Member::where('id', $order['member_id'])->find();

        if ($member) {
            return ['code' => 1, 'msg' => '获取下单者成功', 'data' => $member];
        } else {
            return ['code' => 0, 'msg' => '获取下单者失败'];
        }
    }

    /**
     * 获取上级链
     * @param $member
     * @return array
     */
    public function getUpList($member)
    {
        if (!$member) {
            return ['code' => 0, 'msg' => '没有会员信息'];
        }

        $list = (new MemberLogic())->getUpperMembers($member, []);

        if ($list) {
            return ['code' => 1, 'msg' => '获取上级链成功', 'data' => $list];
        } else {
            return ['code' => 0, 'msg' => '获取上级链失败'];
        }
    }

    /**
     * 获取下级链
     * @param $member
     * @return array
     */
    public function getSonList($member)
    {
        if (!$member) {
            return ['code' => 0, 'msg' => '没有会员信息'];
        }

        $list = (new MemberLogic())->getDownMembers($member, 10);

        if ($list) {
            return ['code' => 1, 'msg' => '获取下级链成功', 'data' => $list];
        } else {
            return ['code' => 0, 'msg' => '获取下级链失败'];
        }
    }

}